package com.example.baudusdk;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: zouren
 * @date: 2021/5/29
 * @description:
 */
public class Test {
    public static void tt(String path,String newPath){
        List<DataEx> list = EasyExcel.read(getInputStream(path), DataEx.class,new DataExListener()).sheet(0).doReadSync();

        list.stream().forEach(row->{
            JSONObject location = EntCoordSyncJob.getCoordinate(row.getAddress());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(location!=null){
                row.setLat(location.getString("lng"));
                row.setLng(location.getString("lat"));
            }else{
                 location = EntCoordSyncJob.getCoordinate(row.getStoreName());
                if(location!=null){
                    row.setLat(location.getString("lng"));
                    row.setLng(location.getString("lat"));
                }
            }
            System.out.println(row);
        });


        // 这里 需要指定写用哪个class去写，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
        // 如果这里想使用03 则 传入excelType参数即可
        EasyExcel.write(newPath, DataEx.class).sheet(0).doWrite(list);

    }
    private static InputStream getInputStream(String fileName) {
        try {
            return new FileInputStream(new File(fileName));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {

        Test.tt("D://ttttt.xlsx","D://ttttt2.xlsx");
    }
}
